<?php
/*--------------------------
	file:	xml.lib
	intro:	xml支持底层函数库
--------------------------*/
/*--------------------------
	function:		将xml转换为数组
	@param: $xml	文件路径
	return: array
----------------------------*/
function simplexml2array($xml) {
   if (get_class($xml) == 'SimpleXMLElement') {
         $attributes = $xml->attributes();
       foreach($attributes as $k=>$v) {
           if ($v) $a[$k] = (string) $v;
       }
         $x = $xml;
         $xml = get_object_vars($xml);
   }
   if (is_array($xml)) {
       if (count($xml) == 0) return (string) $x; // for CDATA
         foreach($xml as $key=>$value) {
             $r[$key] = simplexml2array($value);
             // original line instead of the following if statement: 
             //$r[$key] = simplexml2ISOarray($value);
             if ( !is_array( $r[$key] ) ) $r[$key] = $r[$key];
       }
       if (isset($a)) $r['@'] = $a;    // Attributes
         return $r;
   }
   return (string) $xml;
}
?>